package com.ruoyi.assemble.common.utils;/*
package cn.com.victorysoft.imr.utils;

import cn.hutool.core.bean.BeanUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

*/
/**
 * @author yuqinghai
 *//*

public class CreateTreeJson {
    */
/**
     * 转换成tree json
     * @param list 传进来的地区list
     * @param rootId 最高级别的id
     * @param pIdName 父级字段取值名称
     * @param idName id字段取值名称
     * @return
     *//*

    public static List getTreeJson(List<? extends Object> list, String rootId, String pIdName,String idName,String name) {
        List recursionList;
        List listTree = new ArrayList();
        for (int i = 0; i< list.size(); i++) {
            //bean 转换为 map 正常传递正常list<Map>，就不用做该操作
            Map<String, Object> map = BeanUtil.beanToMap(list.get(i));
            String parentId = map.get(pIdName)==null?"":map.get(pIdName).toString();
            if (parentId.equals(rootId)) {
                Map m = new HashMap();
                for (String str : map.keySet()) {
                    if(idName.equals(str)){
                        m.put("id", map.get(str));
                    }else if(name.equals(str)){
                        m.put("label", map.get(str));
                    }else if(pIdName.equals(str)){
                        m.put("pid", map.get(str));
                    }
                }
                recursionList = getTreeJson(list, map.get(idName).toString(),pIdName,idName,name);
                if (recursionList.size() > 0) {
                    m.put("children", recursionList);
                }
                listTree.add(m);
            }
        }
        return listTree;
    }

    public static void main(String args[]){
       */
/* List<CommonQueryHead> list = new ArrayList<>();
        CommonQueryHead a = new CommonQueryHead();
        a.setOrgId("A");
        a.setParentOrgId("0");
        a.setOrgName("山西");
        list.add(a);
        a = new CommonQueryHead();
        a.setOrgId("A1");
        a.setParentOrgId("A");
        a.setOrgName("晋南");
        list.add(a);
        a = new CommonQueryHead();
        a.setOrgId("A2");
        a.setParentOrgId("A");
        a.setOrgName("晋西");
        list.add(a);
        a = new CommonQueryHead();
        a.setOrgId("A11");
        a.setParentOrgId("A1");
        a.setOrgName("晋南1");
        list.add(a);
        a = new CommonQueryHead();
        a.setOrgId("A12");
        a.setParentOrgId("A1");
        a.setOrgName("晋南2");
        list.add(a);
        a = new CommonQueryHead();
        a.setOrgId("A21");
        a.setParentOrgId("A2");
        a.setOrgName("晋西1");
        list.add(a);
        a = new CommonQueryHead();
        a.setOrgId("A22");
        a.setParentOrgId("A2");
        a.setOrgName("晋西2");
        list.add(a);
       List aaa = getTreeJson(list,"A","parentOrgId","orgId","orgName");
       Map map = new HashMap();
       map.put("id","A");
       map.put("label","山西");
       map.put("children",aaa);
       System.out.println(map);*//*

    }
}
*/
